import { baseUrl } from './config.js'

// 封装请求方法
export const request = (url, method = 'GET', data = {}) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: baseUrl + url,
      method: method,
      data: data,
      header: {
        'content-type': 'application/json'
      },
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data)
        } else {
          reject(res)
        }
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}

// 封装GET请求
export const get = (url, data = {}) => {
  return request(url, 'GET', data)
}

// 封装POST请求
export const post = (url, data = {}) => {
  return request(url, 'POST', data)
}